package com.kuang.gulimall.ware.dao;

import com.kuang.gulimall.ware.entity.WareSkuEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 商品库存
 *
 * @author xiangmou
 * @email 1140968804@qq.com
 * @date 2021-05-05 20:27:37
 */
@Mapper
public interface WareSkuDao extends BaseMapper<WareSkuEntity> {

    void addStock(@Param("skuId") Long skuId, @Param("wareId") Long wareId, @Param("skuNum") Integer skuNum);

    Long countNum(@Param("sku") Long sku);

    //SELECT ware_id FROM wms_ware_sku WHERE sku_id=1 AND stock-stock_locked>0
    List<Long> ListWareIdHasSkuStock(@Param("skuId") Long skuId);

    //UPDATE wms_ware_sku SET stock_locked = stock_locked+2 WHERE sku_id=2 AND ware_id=2 AND stock-stock_locked>=2
    // ,这里要大于最小值，不然1件商品就减成负的了
    Long lockSkuStock(@Param("skuId") Long skuId, @Param("num") Integer num, @Param("wareId") Long wareId);

    void unlockStock(@Param("skuId") Long skuId, @Param("wareId") Long wareId, @Param("num") Integer num);
}
